﻿@model IEnumerable<CodeGeneratorLibrary.DAL.GrammWord>

@{
  ViewBag.Title = "Word";
	IEnumerable<CodeGeneratorLibrary.DAL.GrammNumberGroup> numberGroups = ViewBag.NumberGroup;
	IEnumerable<CodeGeneratorLibrary.DAL.GrammDeclension> declensions = ViewBag.Declension;
}

<h2>@ViewBag.Alias</h2>

@using (Html.BeginForm("Word", "Options")){
	<input name="alias" type="hidden" value="@ViewBag.Alias" />
	<table style="border-style:none;" >
		<thead>
			<tr>
				<td></td>
				@foreach (var num in numberGroups){
					<td>@num.Name</td>
				}
				<td></td>
			</tr>
		</thead>
		@foreach (var dec in declensions){
		 var numWords = Model.Where(x => x.DeclensionId == dec.Id).ToList();
			<tr>
				<td>@dec.Name</td>

				@foreach (var num in numberGroups){
					var value = numWords.SingleOrDefault(x => x.NumberGroupId == num.Id);
					string str = value != null ? value.Word : string.Empty;

					<td>@Html.TextBox(string.Format("{0}_{1}", num.Id, dec.Id), str)</td>
				}

				<td>@dec.Question&nbsp;(@dec.HelpWord)</td>
			</tr>
	 }
	</table>
	
	<input type="submit" value="Сохранить" />
}